package com.lzh.chatnote.chat.dao;

import com.lzh.chatnote.chat.domain.entity.Room;
import com.lzh.chatnote.chat.mapper.RoomMapper;
import com.lzh.chatnote.chat.service.RoomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 房间表/会话表 服务实现类
 * </p>
 *
 * @author lzh
 * @since 2025-09-25
 */
@Service
public class RoomDao extends ServiceImpl<RoomMapper, Room> {

    public Room queryAllRoom() {
        return lambdaQuery()
                .eq(Room::getId, 1)
                .one();
    }

    public List<Room> queryBatchRoomByIds(List<Long> keys) {
        return lambdaQuery().in(Room::getId, keys).list();
    }

    public void reflushLastMsgIdAndTime(Long roomId, Long id, LocalDateTime createTime) {
         lambdaUpdate()
                .eq(Room::getId, roomId)
                .set(Room::getLastMsgId, id)
                .set(Room::getActiveTime, createTime)
                .update();
    }
}
